import { getMaintainerInfo, setMaintainerInfo } from '@/utils/storage'
import { getMaintainerInfoService } from '@/api/maintainer'
export default ({
  namespaced: true,
  state: {
    // 用户个人信息
    maintainerInfo: getMaintainerInfo(),
    baseInfo: {
      maintainer_email: '',
      nickname: '',
      age: '',
      gender: '',
      avatar: '',
      phone: '',
      service_address: '',
      service_type: ''
    }
  },
  mutations: {
    setMaintainerInfo (state, newUserInfo) {
      state.maintainerInfo = newUserInfo
      setMaintainerInfo(newUserInfo)
    },
    setBaseInfo (state, newInfo) {
      state.baseInfo = newInfo
    },
    setAvatar (state, newAvatar) {
      state.baseInfo.avatar = newAvatar
    }
  },
  getters: {
    getBaseInfo (state) {
      return state.baseInfo
    },
    getMAvatar (state) {
      return state.baseInfo.avatar
    }
  },
  actions: {
    async getMaintainerInfoService (context) {
      const res = await getMaintainerInfoService()
      context.commit('setBaseInfo', res.data)
    }
  }
})
